package org.test.updownload;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 
 * 应答ajax请求的，实时拿到statue（通过session
 * Servlet implementation class ProgressUploadServlet
 */
public class ProgressUploadServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ProgressUploadServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		response.setHeader("Cache-Control", "no-store");
		response.setHeader("Pragrma","no-cache");
		response.setDateHeader("Expires", 0);
		//取到statue
		UploadStatus status = (UploadStatus) request.getSession(true).getAttribute("uploadstatus");
		
		if(status==null){
			//没有这个对象，没有上传信息
			response.getWriter().println("没有上传信息");
			return;
		}
		System.out.println(status.getBytesRead());
		System.out.println(status.getContentlength());
		response.getWriter().println(status.getBytesRead());//上传了多少
		response.getWriter().println(status.getContentlength());
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
